//
//  VolunteerRecordViewController.m
//  MemberProject
//
//  Created by macbook on 15/4/13.
//  Copyright (c) 2015年 MAC OS X. All rights reserved.
//

#import "VolunteerRecordViewController.h"
#import "VolunteerInputViewController.h"
#import "VolunteerRecordViewCell.h"
#import "ChoiceDateView.h"
#import "RootViewController.h"
#import "ProgressViewController.h"
#import "MJRefresh.h"
#import "VolunteerClaimViewController.h"
#import "ClaimProgressViewController.h"
#import "ClaimPerInfoViewController.h"
#define ClaimBtnTag   2000

@interface VolunteerRecordViewController ()<UITableViewDelegate,UITableViewDataSource,RefreshTableDelegate>

@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (strong,nonatomic)NSMutableArray *titleSizeArr;
@property (strong,nonatomic)NSMutableArray *groupSizeArr;
@property (strong,nonatomic)NSMutableArray *AddressSizeArr;
@property(strong,nonatomic)NSMutableArray *dataArr;
@property (strong,nonatomic)ChoiceDateView *dateView;
@property (strong,nonatomic)NSDateFormatter *dateFormatter;
@property (copy,nonatomic) NSString *selectDateStr;
@property (strong,nonatomic) MJRefreshHeaderView *header;

@property (assign,nonatomic) NSInteger tableViewRow;

@property (strong,nonatomic) NSMutableArray *allArr;
@end

@implementation VolunteerRecordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title=@"志愿记录";
    self.tableView.dataSource=self;
    self.tableView.delegate=self;
    [self.tableView registerNib:[UINib nibWithNibName:@"VolunteerRecordViewCell" bundle:nil] forCellReuseIdentifier:@"CellIdentifier"];
    
    [self setupData];
    [self addBack];
    [self setupNavigation];
//    [self setupRecordData];
    
    [self setupRefreshData];
    [self.header beginRefreshing];
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changeStatus:) name:ClaimSuccessNotification object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(refreshTable) name:NSNotificationRefreshTableView object:nil];
}

-(void)changeStatus:(NSNotification*)sender
{
    ModelActivity *acty = self.dataArr[self.tableViewRow];
    //没填信息的
    acty.claimStatus = @"0";
    
    [self.dataArr replaceObjectAtIndex:self.tableViewRow withObject:acty];
    
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:self.tableViewRow inSection:0];
    
    [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
    
    
    
}
-(void)setupRefreshData
{
    self.header = [MJRefreshHeaderView header];
    __unsafe_unretained __block VolunteerRecordViewController *recordVC = self;
    self.header.beginRefreshingBlock = ^(MJRefreshBaseView *refreshView) {
        [recordVC setupRecordData];
    };
    self.header.scrollView = self.tableView;
}
-(void)dealloc
{
    [self.header free];
}
-(void)setupData
{
    self.titleSizeArr = [NSMutableArray new];
    self.groupSizeArr = [NSMutableArray new];
    self.AddressSizeArr = [NSMutableArray new];
    self.dataArr=[NSMutableArray new];
//    [self.dataArr addObjectsFromArray:@[@"2015一路向前的一一美丽佛山50公里徒步行。体验佛山城市升级，为佛山点赞",@"美丽佛山"]];
    [self.choiceBtn addTarget:self action:@selector(choiceDate:) forControlEvents:64];
    self.dateFormatter = [[NSDateFormatter alloc]init];
    [self.dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];

    [self.dateFormatter setDateFormat:@"yyyy.MM.dd HH:mm"];
    
    
//    self.serviceHourLabel.text =[NSString stringWithFormat:@"服务总时长:%@小时",[UserInfoManager sharedManager].modelMser.volunteerServiceHours];
}
-(void)setupRecordData
{
    NSString *volunteerCode = [UserInfoManager sharedManager].modelMser.volunteerCode;
    NSLog(@"刷新");
    
    CSVoidBlock removeArrBlock = ^(void){
        [self.dataArr removeAllObjects];
        [self.titleSizeArr removeAllObjects];
        [self.AddressSizeArr removeAllObjects];
        [self.groupSizeArr removeAllObjects];
    };
    
    
    
    [[BuaatVolunteerServerSDK sharedInstance]requestActivityRecord4UnregListWithVolunteerCode:volunteerCode success:^(NSHTTPURLResponse *response, id responseObject) {
        
        
        if ([responseObject isKindOfClass:[NSDictionary class]]) {
            id result = responseObject[@"result"];
            if ([result isKindOfClass:[NSArray class]])
            {
                removeArrBlock();
                NSArray *arr = result;
                NSLog(@"有%d条",arr.count);
                if (arr.count>0) {
                    for (int i=0;i<arr.count-1;i++) {
                        NSDictionary *dic = arr[i];
                        
                        [self.dataArr addObject:[ModelActivity getActivityForDic:dic]];
                        [self refreshTableView:i];
                    }
                    NSDictionary *hoursDic = [arr lastObject];
                    NSString *totalServiceHours = hoursDic[@"totalServiceHours"];
                    
                    self.serviceHourLabel.text =[NSString stringWithFormat:@"服务总时长:%d小时",totalServiceHours.intValue];
                    
                    [self.tableView reloadData];
                }
                
            }else
            {
                [SVProgressHUD showErrorWithStatus:@"获取列表失败" maskType:SVProgressHUDMaskTypeBlack];
            }
        }else
        {
            [SVProgressHUD showErrorWithStatus:@"获取列表失败" maskType:SVProgressHUDMaskTypeBlack];
        }
        [self.header endRefreshing];
    } failure:^(NSHTTPURLResponse *response, NSError *error) {
        [SVProgressHUD showErrorWithStatus:@"网络错误" maskType:SVProgressHUDMaskTypeBlack];
        [self.header endRefreshing];
    }];
}

#pragma mark 筛选日期
-(void)choiceDate:(UIButton *)sender
{
    
    
    
    if (!self.dateView) {
        self.dateView=[[[NSBundle mainBundle] loadNibNamed:@"ChoiceDateView" owner:self options:nil]lastObject];
    }
    
    [self.dateView show:self];
//
//    
    [self.dateView doneActionBlock:^(NSString *submitStr) {
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
        [dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];

        [dateFormatter setDateFormat:@"yyyy-MM-DD HH:mm"];
        NSDate *date = [dateFormatter dateFromString:submitStr];
        self.selectDateStr = submitStr;
        [self.titleSizeArr removeAllObjects];
        [self.AddressSizeArr removeAllObjects];
        [self.groupSizeArr removeAllObjects];
        
        NSMutableArray *newArr = [[NSMutableArray alloc]init];
        for (int i=0; i<self.dataArr.count; i++) {
            ModelActivity *acty = self.dataArr[i];
            if (acty.activityStartPeriod.length>0&&acty.activityEndPeriod.length>0) {
                NSDate *beginDate = [dateFormatter dateFromString:acty.activityStartPeriod];
                NSDate *endDate = [dateFormatter dateFromString:acty.activityEndPeriod];
                
                if ([endDate timeIntervalSinceDate:date]>=0&&[date timeIntervalSinceDate:beginDate]>=0)
                {
                    [self refreshTableView:i];
                    [newArr addObject:acty];
                }
            }
           
            
            
            
            
        }
        
        self.dataArr = newArr;
        [self.tableView reloadData];
        
        [self.dateView backAction];
    }];
}
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    if (self.dateView) {
        [self.dateView backAction];
    }
}
-(void)refreshTableView:(NSInteger)index
{
        ModelActivity *acty = self.dataArr[index];
        NSString *content = acty.activityName;
        CGFloat textHeight = [Utils heightForLabel:content andFont:14 andWidth:SCREEN_WIDTH-49];
        NSNumber *num = [NSNumber numberWithFloat:textHeight];
    
    CGFloat addressHeight = [Utils heightForLabel:acty.activityLocation andFont:14 andWidth:SCREEN_WIDTH-63]+4;
    
    CGFloat groupHeight = [Utils heightForLabel:acty.groupName andFont:14 andWidth:SCREEN_WIDTH-63]+4;
    
    [self.titleSizeArr addObject:num];
    [self.AddressSizeArr addObject:[NSNumber numberWithFloat:addressHeight]];
    [self.groupSizeArr addObject:[NSNumber numberWithFloat:groupHeight]];
}
-(void)setupNavigation
{
//    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"add_button.png"] style:UIBarButtonItemStylePlain target:self action:@selector(chickRightBarButton:)];
    UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 40, 32)];
//    [btn setImageEdgeInsets:UIEdgeInsetsMake(0, 18, 0, 0)];
    [btn setImage:[UIImage imageNamed:@"add_button.png"] forState:0];
    [btn addTarget:self action:@selector(chickRightBarButton:) forControlEvents:64];
//    UIBarButtonItem *rightBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"添加" style:UIBarButtonItemStyleBordered target:self action:@selector(chickRightBarButton:)];
    self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithCustomView:btn];
}
-(void)chickRightBarButton:(UIButton *)sender{
//    VolunteerInputViewController *vc=[[VolunteerInputViewController alloc]init];

//    [self.navigationController pushViewController:vc animated:YES];
    NSArray *menuArr = @[
                         [KxMenuItem menuItem:@"有活动号"
                                        image:nil
                                       target:self
                                       action:@selector(showZbar)],
                         [KxMenuItem menuItem:@"没有活动号"
                                        image:nil
                                       target:self
                                       action:@selector(pushWithOutActivity)],
                         ];
    
    if (menuArr) {
        [KxMenu showMenuInView:self.view
                      fromRect:CGRectMake(sender.x, sender.y-35, sender.width, sender.height)
                     menuItems:menuArr];
    }
    
    
    
//    [self showQz:ActivityStyle];
//    [self getZBarPushBlockStr:^(NSString *str) {
//        [self checkGroupInfo:str];
//    }];
}


#pragma mark 有活动二维码，需要扫一扫
-(void)showZbar
{
    [self showQz:ActivityStyle];
    [self getZBarPushBlockStr:^(NSString *str) {
        [self checkActivityInfo:str];
    }];
    

}

#pragma mark 查询活动信息
-(void)checkActivityInfo:(NSString *)code
{
    [[BuaatVolunteerServerSDK sharedInstance]requestQrcodeActivityInfoWithActivityCode:code success:^(NSHTTPURLResponse *response, id responseObject) {
        if ([responseObject isKindOfClass:[NSDictionary class]]) {
            [SVProgressHUD dismiss];
            id result = responseObject[@"result"];
            if ([result isKindOfClass:[NSDictionary class]]) {
                
                [self pushWithActivity:result];
                
                
                
            }else
            {
                [SVProgressHUD showErrorWithStatus:@"没有该活动信息" maskType:SVProgressHUDMaskTypeBlack];
            }
        }else
        {
            [SVProgressHUD showErrorWithStatus:@"没有该活动信息" maskType:SVProgressHUDMaskTypeBlack];
        }
//        [self pushInput];
        
    } failure:^(NSHTTPURLResponse *response, NSError *error) {
        [SVProgressHUD showErrorWithStatus:@"网络错误" maskType:SVProgressHUDMaskTypeBlack];
    }];
}

-(void)refreshTable
{
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self.header beginRefreshing];
    });

}

#pragma mark 跳到
-(void)pushWithActivity:(NSDictionary *)result
{

    VolunteerInputViewController *vInputVC = [[VolunteerInputViewController alloc]initWithNibName:@"VolunteerInputViewController" bundle:nil];
    vInputVC.refreshDelegate = self;
    [vInputVC setActivityDic:result];
    vInputVC.isAlreadyInputActiveCode = YES;
    [self.navigationController pushViewController:vInputVC animated:YES];
}
#pragma mark 没有的，直接填补登信息
-(void)pushWithOutActivity
{
    VolunteerInputViewController *vInputVC = [[VolunteerInputViewController alloc]initWithNibName:@"VolunteerInputViewController" bundle:nil];
    vInputVC.isAlreadyInputActiveCode = NO;
    vInputVC.refreshDelegate = self;
    [self.navigationController pushViewController:vInputVC animated:YES];
}

//-(void)checkGroupInfo:(NSString *)code
//{
//    [SVProgressHUD showWithStatus:@"加载中.." maskType:SVProgressHUDMaskTypeBlack];
//    NSDictionary *parameters = @{@"token":@"sdfsadfsadfasdf",@"module":@"VoluteerGroup",@"method":@"loadVoluteerGroupBycode",@"requestId":[NSNull new],@"requestParam":@[code]};
//    [Utils requestDic:parameters andRusult:^(id result) {
//        if ([result isKindOfClass:[NSDictionary class]]) {
//            
//            if(![result[@"responseData"] isKindOfClass:[NSNull class]])
//            {
//                [SVProgressHUD dismiss];
//                NSDictionary *responseData = result[@"responseData"];
//                if (responseData&&responseData.allKeys.count>0) {
//                    NSString *groupName = responseData[@"groupName"];
//                    NSString *groupId = responseData[@"groupId"];
//                    VolunteerInputViewController *vc=[[VolunteerInputViewController alloc]init];
//                    [vc setGroupName:groupName];
//                    [vc setGroupCode:groupId];
//                [self.navigationController pushViewController:vc animated:YES];
//                }
//            }else
//            {
//                [SVProgressHUD showErrorWithStatus:@"没有该机构" maskType:SVProgressHUDMaskTypeBlack];
//            }
//            
//            
//        }
//        
//    } andError:^(id result) {
//        [SVProgressHUD showErrorWithStatus:@"网络错误" maskType:SVProgressHUDMaskTypeBlack];
//        
//        
//    }];
//}
#pragma mark - tableView
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSNumber *titleHeight = self.titleSizeArr[indexPath.row];
    NSNumber *groupHeight = self.groupSizeArr[indexPath.row];
    NSNumber *addressHeight = self.AddressSizeArr[indexPath.row];
         return 100+titleHeight.floatValue+groupHeight.floatValue+addressHeight.floatValue;
   
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellIdentifier=@"CellIdentifier";
    VolunteerRecordViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    if (indexPath.row==0) {
        cell.upLine.hidden = YES;
    }else
        cell.upLine.hidden = NO;
    
    if (indexPath.row==self.dataArr.count-1) {
        cell.downLine.hidden = YES;
    }else
    {
        cell.downLine.hidden = NO;
    }
    ModelActivity *acty = self.dataArr[indexPath.row];
    
    if ([acty.claimStatus isEqualToString:@"5"]) {
        
    }
    
    //标题
    cell.titleLabel.text = acty.activityName;
    NSNumber *titleHeight = self.titleSizeArr[indexPath.row];
    NSNumber *groupHeight = self.groupSizeArr[indexPath.row];
    NSNumber *addressHeight = self.AddressSizeArr[indexPath.row];
    cell.titleTextViewHeight.constant = titleHeight.floatValue;
    cell.groupHeight.constant = groupHeight.floatValue;
    cell.addressViewHeight.constant = addressHeight.floatValue;
    
//    if ([acty.activityName isEqualToString:@"试试"]) {
//        
//    }
    //主办方
    cell.UnitLabel.text = acty.groupName;
    
    //时间
    cell.dateLabel.text = [NSString stringWithFormat:@"%@-%@",acty.activityStartPeriod,acty.activityEndPeriod];
    
    [cell.claimBtn addTarget:self action:@selector(claimAction:) forControlEvents:64];
    cell.claimBtn.tag = ClaimBtnTag+indexPath.row;
    
    //地址
    cell.addressLabel.text = acty.activityLocation;
    
    
//    * RECORD_STATUS 记录状态
//    * 0 最后确认
//    * 1 待审核
//    * 2 取消或不通过
//    *
//    *
//    * RECORD_TYPE 记录类型
//    * 1 正常记录
//    * 2 为补登记录
    //状态
    
//    cell.claimBtn.hidden = YES;
//    if ([acty.activityName isEqualToString:@"期末考"]) {
    
//    }
    

    
    cell.claimBtn.hidden = YES;
    
    if (acty.recordStatus!=nil&&![acty.recordStatus isEqualToString:@""]) {
        cell.verifyBtn.hidden = NO;
        switch (acty.recordStatus.intValue) {
            case 0:
            {
                [cell.verifyBtn setImage:[UIImage imageNamed:@"0805_22.png"] forState:0];
                //理赔
                
                BOOL isClaim =[ModelInsurance checkOverTime:acty.activityStartPeriod andEndDate:acty.activityEndPeriod];
                cell.claimBtn.hidden = !isClaim;
                //理赔进度
                if (acty.claimStatus!=nil&&![acty.claimStatus isKindOfClass:[NSNull class]]&&acty.claimStatus.length>0) {
                    
                    NSString *imageName = @"";
                    switch (acty.claimStatus.intValue) {
                        case InitSumitType:
                        {
                            imageName = @"icon_03.png";
                        }
                        break;
                        case AdminConfirmType:
                        {
                            imageName = @"icon_01.png";
                        }
                        break;
                        case NOPassType:
                        {
                            imageName = @"icon_05.png";
                        }
                        break;
                        case AddInfoType:
                        {
                            imageName = @"0805icon.png";
                        }
                        break;
                            case AcceptClaimType:
                        {
                            imageName = @"icon_02.png";
                        }
                            break;
                            case EndClaimType:
                        {
                            imageName = @"icon_04.png";
                        }
                            break;
                    }
                    [cell.claimBtn setImage:[UIImage imageNamed:imageName] forState:0];
                    
                    
                }else
                {
                    //理赔
                    [cell.claimBtn setImage:[UIImage imageNamed:@"lp_button.png"] forState:0];
                }
                
            }
                break;
            case 1:
                [cell.verifyBtn setImage:[UIImage imageNamed:@"0805_15.png"] forState:0];
                break;
            case 2:
                [cell.verifyBtn setImage:[UIImage imageNamed:@"001_27.png"] forState:0];
                break;

        }
    }else
    {
        cell.verifyBtn.hidden = YES;
    }
    
    //服务时长
    cell.timeLabel.text = [NSString stringWithFormat:@"%d小时",acty.serviceHours.intValue];
    
    //服务积分
    cell.scorelabel.text = [NSString stringWithFormat:@"%d积分",acty.serviceScore.intValue];

    
    
    
    cell.contentHeight.constant = 85+groupHeight.floatValue+addressHeight.floatValue;
    cell.privateBtn.hidden = YES;
    
    
    
    return cell;
}
#pragma mark 理赔操作
-(void)claimAction:(UIButton *)sender
{
    ModelActivity *acty = self.dataArr[sender.tag- ClaimBtnTag];
    //没填信息的
    self.tableViewRow = sender.tag- ClaimBtnTag;
    //没完成
    void(^unFinishBlock)() = ^(void)
    {
    [UserInfoManager sharedManager].userClaimInput = [UserClaimInput initData];
    [UserInfoManager sharedManager].userClaimInput.activityBeginDate = acty.activityStartPeriod;
    [UserInfoManager sharedManager].userClaimInput.activityEndDate = acty.activityEndPeriod;
//        [UserInfoManager sharedManager].userClaimInput.insuranceId = [UserInfoManager sharedManager].userInsurance.insuranceId;
        [UserInfoManager sharedManager].userClaimInput.recordId = acty.recordId;
        
    VolunteerClaimViewController *claimVC = [[VolunteerClaimViewController alloc]initWithNibName:@"VolunteerClaimViewController" bundle:nil];
        [self.navigationController pushViewController:claimVC animated:YES];

    };
    
    
    
    //已完成
    void(^FinishBlock)()= ^(NSDictionary *dic)
    {
        if (acty.claimStatus.intValue ==AddInfoType)
        {
            ClaimPerInfoViewController *perInfoVC = [[ClaimPerInfoViewController alloc]initWithNibName:@"ClaimPerInfoViewController" bundle:nil];
            perInfoVC.isUpdate=YES;
            ModelClaimInfo *modelClaim = [ModelClaimInfo getClaimForDic:dic];
            
            [UserInfoManager sharedManager].userClaimInput = [UserClaimInput initData];
            [UserInfoManager sharedManager].userClaimInput.claimId = modelClaim.claimId;
            [UserInfoManager sharedManager].userClaimInput.activityBeginDate = acty.activityStartPeriod;
            [UserInfoManager sharedManager].userClaimInput.activityEndDate = acty.activityEndPeriod;
            [UserInfoManager sharedManager].userClaimInput.recordId = acty.recordId;
            [UserInfoManager sharedManager].userClaimInput.dangerDate=modelClaim.dangerDate;
            [UserInfoManager sharedManager].userClaimInput.bankAccount=modelClaim.bankAccount;
            [UserInfoManager sharedManager].userClaimInput.bankAccountCity=modelClaim.bankAccountCity;
            [UserInfoManager sharedManager].userClaimInput.bankName=modelClaim.bankName;
            [UserInfoManager sharedManager].userClaimInput.bankBranchName=modelClaim.bankBranchName;
            [UserInfoManager sharedManager].userClaimInput.bankSubBranchName=modelClaim.bankSubBranchName;
            [UserInfoManager sharedManager].userClaimInput.contactAddress=modelClaim.contactAddress;
            [UserInfoManager sharedManager].userClaimInput.applyCost=modelClaim.applyCost;
            [UserInfoManager sharedManager].userClaimInput.bankAccountName=modelClaim.bankAccountName;
            
            NSMutableArray *arrM=[NSMutableArray array];
            for(int i=0;i<7;i++){
                [arrM addObject:@[]];
            }
            [UserInfoManager sharedManager].userClaimInput.images=arrM;
            [self.navigationController pushViewController:perInfoVC animated:YES];
            
            
        }else
        {
            
            ClaimProgressViewController *progressVC = [[ClaimProgressViewController alloc]initWithNibName:@"ClaimProgressViewController" bundle:nil];
            
            ModelClaimInfo *modelClaim = [ModelClaimInfo getClaimForDic:dic];
            [progressVC setModelClaim:modelClaim];
            [self.navigationController pushViewController:progressVC animated:YES];
            
            
            /*
            ClaimPerInfoViewController *perInfoVC = [[ClaimPerInfoViewController alloc]initWithNibName:@"ClaimPerInfoViewController" bundle:nil];
            perInfoVC.isUpdate=YES;
            ModelClaimInfo *modelClaim = [ModelClaimInfo getClaimForDic:dic];
            
            [UserInfoManager sharedManager].userClaimInput = [UserClaimInput initData];
            [UserInfoManager sharedManager].userClaimInput.claimId = modelClaim.claimId;
            [UserInfoManager sharedManager].userClaimInput.activityBeginDate = acty.activityStartPeriod;
            [UserInfoManager sharedManager].userClaimInput.activityEndDate = acty.activityEndPeriod;
            [UserInfoManager sharedManager].userClaimInput.recordId = acty.recordId;
            [UserInfoManager sharedManager].userClaimInput.dangerDate=modelClaim.dangerDate;
            [UserInfoManager sharedManager].userClaimInput.bankAccount=modelClaim.bankAccount;
            [UserInfoManager sharedManager].userClaimInput.bankAccountCity=modelClaim.bankAccountCity;
            [UserInfoManager sharedManager].userClaimInput.bankName=modelClaim.bankName;
            [UserInfoManager sharedManager].userClaimInput.bankBranchName=modelClaim.bankBranchName;
            [UserInfoManager sharedManager].userClaimInput.bankSubBranchName=modelClaim.bankSubBranchName;
            [UserInfoManager sharedManager].userClaimInput.contactAddress=modelClaim.contactAddress;
            [UserInfoManager sharedManager].userClaimInput.applyCost=modelClaim.applyCost;
            [UserInfoManager sharedManager].userClaimInput.bankAccountName=modelClaim.bankAccountName;
            
            NSMutableArray *arrM=[NSMutableArray array];
            for(int i=0;i<7;i++){
                [arrM addObject:@[]];
            }
            [UserInfoManager sharedManager].userClaimInput.images=arrM;
            [self.navigationController pushViewController:perInfoVC animated:YES];
             
             */
        }
        
        
        
    };
    
    
    
    
    
    
    if (acty.claimStatus!=nil&&![acty.claimStatus isKindOfClass:[NSNull class]]&&acty.claimStatus.length>0) {
        
//        if (acty.claimStatus.intValue==5) {
//            unFinishBlock();
//        }else
//        {
        
            [SVProgressHUD showWithStatus:@"加载中" maskType:SVProgressHUDMaskTypeBlack];
            [[BuaatVolunteerServerSDK sharedInstance]requestInsuranceSearchClaimResultWithVolunteerCode:[UserInfoManager sharedManager].modelMser.volunteerCode recordId:acty.recordId Success:^(NSHTTPURLResponse *response, id responseObject) {
                [SVProgressHUD dismiss];
                id result = responseObject[@"result"];
                if ([result isKindOfClass:[NSArray class]]) {
                    NSArray *arr = result;
                    if (arr.count==0){
                        [Utils showAlert:@"查不到相关进度"];
                    }else{
                        
                        
                        FinishBlock([arr lastObject]);
                    }
                }
            } failure:^(NSHTTPURLResponse *response, NSError *error) {
                [SVProgressHUD showErrorWithStatus:@"网络错误" maskType:SVProgressHUDMaskTypeBlack];
            }];
            
            
//        }
        
        
        
    }else
    {
        unFinishBlock();
    }
    
    

    

    

    
   
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
@end








@implementation ModelActivity

+(ModelActivity *)getActivityForDic:(NSDictionary *)dic
{
    ModelActivity *activity = [ModelActivity new];
    [activity reflectDataFromOtherObject:dic];
    activity.activityStartPeriod = [Utils changeDateFromService:activity.activityStartPeriod];
    activity.activityEndPeriod = [Utils changeDateFromService:activity.activityEndPeriod];
    
//    if (activity.activityStartPeriod.length>3) {
//        activity.activityStartPeriod = [activity.activityStartPeriod substringToIndex:[activity.activityStartPeriod length] - 3];
//    }
//    if (activity.activityEndPeriod.length>3) {
//        activity.activityEndPeriod = [activity.activityEndPeriod substringToIndex:[activity.activityEndPeriod length] - 3];
//    }
    
    
    return activity;
}

@end



